/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.transfer.service.impl;

import me.zhengjie.modules.transfer.domain.TransferAc11;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.transfer.service.TransferAc11Service;
import me.zhengjie.modules.transfer.domain.dto.TransferAc11QueryCriteria;
import me.zhengjie.modules.transfer.mapper.TransferAc11Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author lzw
* @date 2025-05-27
**/
@Service
@RequiredArgsConstructor
public class TransferAc11ServiceImpl extends ServiceImpl<TransferAc11Mapper, TransferAc11> implements TransferAc11Service {

    private final TransferAc11Mapper transferAc11Mapper;

    @Override
    public PageResult<TransferAc11> queryAll(TransferAc11QueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(transferAc11Mapper.findAll(criteria, page));
    }

    @Override
    public List<TransferAc11> queryAll(TransferAc11QueryCriteria criteria){
        return transferAc11Mapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(TransferAc11 resources) {
        transferAc11Mapper.insert(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(TransferAc11 resources) {
        TransferAc11 transferAc11 = getById(resources.getAaz656());
        transferAc11.copy(resources);
        transferAc11Mapper.updateById(transferAc11);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<String> ids) {
        transferAc11Mapper.deleteBatchIds(ids);
    }

    @Override
    public void download(List<TransferAc11> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TransferAc11 transferAc11 : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("转移业务流程信息ID", transferAc11.getAaz655());
            map.put("操作原因", transferAc11.getAae186());
            map.put("备注", transferAc11.getAae013());
            map.put("经办人", transferAc11.getAae011());
            map.put("经办时间", transferAc11.getAae036());
            map.put("业务日志ID", transferAc11.getAaz002());
            map.put("数据表来源", transferAc11.getBae038());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
